package com.cskaoyan.config;


import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.PutObjectResult;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.cskaoyan.utils.CharUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.InputStream;
import java.rmi.ServerException;

/**
 * @author zjq
 * 阿里云服务组件
 * @date 2022/11/20 14:49
 */
@Component
@ConfigurationProperties(prefix = "aliyun")
@Data
public class AliyunComponent {

    // 张家齐账号
    private String accessKeyId = "LTAI5t9JAW72z7QoEisYfdPw";
    private String accessKeySecret ="OKtkCE81X9BKokjRstbhPCEwUkRajS";

    // 石头老师账号
    // String accessKeyId = "LTAI5t8gpxPTCR6W58RnZq4u";
    // String accessKeySecret = "mVPbpbxia0JQotb7HyJAREV8QUuq8h";
    @Autowired
    Oss oss;

    // @Autowired
    // Sms sms;

    /**
     * @author zjq
     * Oss文件上传
     * @date 2022/11/20 15:09
     */
    public OSSClient getOSSClient() {
        OSSClient ossClient = new OSSClient(oss.getEndPoint(), accessKeyId, accessKeySecret);
        return ossClient;
    }

    public PutObjectResult fileUpload(String filename, File file) {
        OSSClient ossClient = getOSSClient();
        PutObjectResult putObjectResult = ossClient.putObject(oss.getBucket(), filename, file);
        return putObjectResult;
    }

    public PutObjectResult fileUpload(String filename, InputStream file) {
        OSSClient ossClient = getOSSClient();
        PutObjectResult putObjectResult = ossClient.putObject(oss.getBucket(), filename, file);
        return putObjectResult;
    }

}
